package com.jmyd.coupon.server.controller;

import com.jmyd.commons.base.vo.PageBean;
import com.jmyd.commons.base.vo.Result;
import com.jmyd.commons.constants.BaseUrlConstants;
import com.jmyd.coupon.server.domain.dto.SceneActivityDto;
import com.jmyd.coupon.server.domain.dto.SceneActivityQueryDto;
import com.jmyd.coupon.server.domain.vo.SceneActivityVo;
import com.jmyd.coupon.server.service.ISceneActivityService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 活动管理相关接口
 *
 * @author samphin
 * @date 2019-8-28 16:24:10
 */
@RestController
@RequestMapping(BaseUrlConstants.BASE_ADMIN_PREFIX + "/activity")
public class SceneActivityController {

    @Resource
    private ISceneActivityService sceneActivityService;

    /**
     * 创建活动信息
     *
     * @param dto
     * @author samphin
     * @since 2021-7-15 10:27:23
     */
    @PostMapping
    public Result<Boolean> save(@RequestBody @Validated SceneActivityDto dto) {
        boolean bl = this.sceneActivityService.save(dto);
        return bl ? Result.ok() : Result.failure();
    }

    /**
     * 修改活动信息
     *
     * @param dto
     * @author samphin
     * @since 2021-7-15 10:27:23
     */
    @PutMapping
    public Result<Boolean> update(@RequestBody @Validated SceneActivityDto dto) {
        boolean bl = this.sceneActivityService.save(dto);
        return bl ? Result.ok() : Result.failure();
    }

    /**
     * 删除活动信息
     *
     * @param id 活动id
     * @author samphin
     * @since 2021-7-15 10:27:23
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteById(@PathVariable Long id) {
        boolean bl = this.sceneActivityService.deleteById(id);
        return bl ? Result.ok() : Result.failure();
    }

    /**
     * 批量删除活动信息
     *
     * @param ids 活动ID集合
     * @author samphin
     * @since 2021-7-15 10:27:23
     */
    @DeleteMapping
    public Result<Boolean> deleteBatch(@RequestBody List<Long> ids) {
        boolean bl = this.sceneActivityService.deleteBatch(ids);
        return bl ? Result.ok() : Result.failure();
    }

    /**
     * 查询活动分页列表
     *
     * @param queryDto 查询条件
     * @author samphin
     * @since 2021-7-15 10:27:23
     */
    @GetMapping
    public Result<PageBean<SceneActivityVo>> queryPageList(SceneActivityQueryDto queryDto) {
        PageBean<SceneActivityVo> pageBean = this.sceneActivityService.queryPageList(queryDto);
        return new Result<>(pageBean);
    }

    /**
     * 查询活动详情
     *
     * @param id 活动ID
     * @author samphin
     * @since 2021-7-15 10:27:23
     */
    @GetMapping("/{id}")
    public Result<SceneActivityVo> queryById(@PathVariable Long id) {
        SceneActivityVo vo = this.sceneActivityService.queryById(id);
        return new Result<>(vo);
    }
}
